package com.x.config;

import com.ulisesbocchio.jasyptspringboot.annotation.ConditionalOnMissingBean;
import org.jasypt.encryption.StringEncryptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * the class of advance
 *
 * 自定义jasypt加解密法，加密前后缀需要的配置类
 * <p>
 * .
 *
 * @author little_lunatic
 * @date 2024-06-12
 */
@Configuration
public class JasyptConfiguration {

    /**
     * 这里的名字必须是jasyptStringEncryptor,不能改动
     *
     * @param propertyDetector
     * @return
     */
    @Bean(name = "jasyptStringEncryptor")
    @ConditionalOnMissingBean
    public StringEncryptor stringEncryptor(MyEncryptablePropertyDetector propertyDetector){
        return new MyEncryptor(propertyDetector);
    }

    /**
     * 这里的名字必须是encryptablePropertyDetector,不能改动
     *
     * @return
     */
    @Bean(name = "encryptablePropertyDetector")
    @ConditionalOnMissingBean
    public MyEncryptablePropertyDetector encryptablePropertyDetector() {
        return new MyEncryptablePropertyDetector();
    }
}
